<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv=content-type content="text/html; charset=UTF-8">
<base href="<%=basePath%>">
<title>YP.ShO购</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> 
<link rel="stylesheet" href="css/bootstrap.css"></link>
<link rel="stylesheet" href="css/style.css"></link>
<link rel="stylesheet" href="css/myButton.css"></link>
<link rel="stylesheet" href="css/sellerStyle.css"></link>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easydropdown.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript">
	function changeGoodsDelete(id,isDelete,operation) {
		if (!confirm("您真的要"+operation+"此商品么？")) {
			return false;
		}
		$.ajax({
			url : "changeGoodsDelete.action",
			type : "post",
			data : {
				"goods.id" : id,
				"goods.isDelete" : isDelete
			},
			success : function(data) {
				var flag = JSON.parse(data).flag;
				if (flag=="success") {
					alert("已成功"+operation);
					window.location.reload();
				} else {
					alert(operation+"失败");
				}
			},
			error : function() {
				alert("与服务器同步失败");
			}
		});
	}
	
	function goodsView(id) {
		window.open("<%=basePath%>goodDetail.action?gid="+id);
	}
	
	function editGoods(id) {
		window.open("<%=basePath%>viewGoods.action?goods.id="+id);
	}
	
	function addGoods() {
		window.open("<%=basePath%>addGoods.action");
	}
</script>
<style type="text/css">
.form p {
	margin-bottom: 15px;
}

.form label {
	width: 8em;
}
</style>
</head>
<body>
	<%@include file="../common/head.jsp"%>
	<div class="menu"></div>
	<div class="men">
		<div class="container">
			<div class="col-md-3 sidebar">
				<div class="block block-layered-nav">
					<div class="block-title">
						<strong><span>我的YPShO购</span></strong>
					</div>
					<div class="block-content">
						<dl id="narrow-by-list">
							<dt class="last odd">用户中心</dt>
							<dd class="last odd">
								<ol>
									<li><a href="userInforView">个人信息管理</a></li>
								</ol>
							</dd>
							<dt class="last odd">我是买家</dt>
							<dd class="last odd">
								<ol>
									<li><a href="userOrders">我的订单管理</a></li>
									<li><a href="userCart">我的购物车</a></li>
								</ol>
							</dd>
							<dt class="last odd">我是卖家</dt>
							<dd class="last odd">
								<ol>
									<li><a href="sellerOrders">我的订单管理</a></li>
									<li><a href="sellerGoods" style="color:#e05b5b">我的商品管理</a></li>
								</ol>
							</dd>
						</dl>
					</div>
				</div>
			</div>
			<div class="col-md-9">
				<div class="mens-toolbar">
					<div class="sort">
						<div class="sort-by">
							<label>我的商品</label>
						</div>
					</div>
					<div class="sort" style="float:right">
						<div class="sort-by" style="float:right">
							<input type="button" class="button green medium" style="margin-top: 0px" onclick="addGoods()" value="新增商品">
						</div>
					</div>
				</div>
				<div class="form">
					<table>
						<tr height="37px" style="background: #009999;">
							<td width="80px"></td>							
							<td style="width: 348px;">商品</td>
							<td align="center" style="width: 80px;">售价</td>
							<td align="center" style="width: 130px;">卖家</td>
							<td align="center" style="width: 130px;">品牌</td>
							<td align="center" style="width: 57px;">操作</td>
						</tr>
						<tr>
							<td colspan="6" style="height: 15px">
								<hr style="height:2px;background-color: rgb(0,153,153);">
							</td>
						</tr>
						<s:iterator value="Glist" id="goods">
							<tr height="80px" style="border: rgb(0,153,153) solid 0.25px;">
								<td>
									<s:if test="#goods.img==null||#goods.img==''">
									<img alt="商品图片未能正确加载" src="./images/pic1.jpg" width="80px">
									</s:if><s:else>
									<img alt="商品图片未能正确加载" src="<s:property value="#goods.img"/>" width="80px">
									</s:else>
								</td>
								<td onclick="goodsView(<s:property value="#goods.id "/>)"><s:property value="#goods.goodsname"/></td>
								<td align="center"><s:property value="#goods.price"/></td>
								<td align="center"><s:property value="#goods.user.name"/></td>
								<td align="center"><s:property value="#goods.brand.brandname"/></td>
								<td align="center">
									<s:if test="#goods.isDelete==0">
									<a href="javascript:void(0);" class="button white small" onclick="changeGoodsDelete(<s:property value="#goods.id "/>,1,'下架')" style="margin-bottom: 2px;">下架</a><br>
									</s:if>
									<s:else>
									<a href="javascript:void(0);" class="button white small" onclick="changeGoodsDelete(<s:property value="#goods.id "/>,0,'上架')" style="margin-bottom: 2px;">上架</a><br>
									</s:else>
									<a href="javascript:void(0);" class="button green small" onclick="editGoods(<s:property value="#goods.id "/>)" style="margin-top: 2px;">修改</a>
								</td>
							</tr>
						</s:iterator>
					</table>
				</div>
			</div>
		</div>
	</div>

	<%@include file="../common/footer.jsp"%>

</body>
</html>
